package com.itcoon.cloud.framework.transform;/**
 * @author Athric Yu
 * 2024/9/30
 **/

import com.itcoon.cloud.framework.transform.converter.Converter;
import com.itcoon.cloud.framework.transform.converter.ConverterFactory;
import com.itcoon.cloud.framework.transform.definition.InjectDefinition;
import com.itcoon.cloud.framework.transform.enums.TransformFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

/**
 *
 *
 * @author Athric Yu
 * 2024/9/30
 **/
public class DefaultMethodAssembler<T, R> implements MethodAssembler<T, R>{

    private static final Logger log = LoggerFactory.getLogger(DefaultMethodAssembler.class);

    private final ConverterFactory converterFactory;

    public DefaultMethodAssembler(ConverterFactory converterFactory) {
        this.converterFactory = converterFactory;
    }

    @Override
    public R assemble(T source, Class<R> targetClass, Type[] actualTypes, String[] ignoreProperties, List<InjectDefinition> injectDefinitions, TransformFeature... features) {
        Converter<T, R> converter = converterFactory.getConverter(source, targetClass);
        return converter.convert(source, null, targetClass, actualTypes, ignoreProperties, injectDefinitions, Collections.emptyList(), features);
    }
}
